package InterviewTest.q0102_CheckPermutation;

public class Solution {
    /*
    除此之外还有一种方法
    将两个字符串转为字符数组 然后排序后检验是否相等
    时间复杂度达到nlogn 空间为logn
     */
    public boolean CheckPermutation(String s1, String s2) {
        int[] chars = new int[26];
        for (int i = 0; i < s1.length() & i < s2.length(); i++) {
            chars[s1.charAt(i) - 'a'] += 1;
            chars[s2.charAt(i) - 'a'] -= 1;
        }

        for (int i = 0; i < chars.length; i++) {
            if (chars[i] != 0) return false;
        }

        return s1.length() == s2.length();
    }
}
